from __future__ import division
import hashlib

def getNumberOfDigits(n):
    e = 0
    while n / 10 ** e > 1:
        e += 1
    return e

def getNumberWithDummy(number):
    n = 10 - getNumberOfDigits(number)
    zero = "0"
    return zero * n + str(number)

def saveGame(player):
    
    f = open('save.dat', 'w')

    strengthOnFile = 0

    dexterityOnFile = 10

    vitalityOnFile = 20

    energyOnFile = 30

    maxHealthOnFile = 40

    healthOnFile = 50

    maxManaOnFile = 60

    manaOnFile = 70

    defenseOnFile = 80

    magdefOnFile = 90

    atkMeleeMinOnFile = 100

    atkMeleeMaxOnFile = 110

    atkRangedMinOnFile = 120

    atkRangedMaxOnFile = 130

    atkMagicMinOnFile = 140

    atkMagicMaxOnFile = 150

    goldOnFile = 160

    evasionOnFile = 170

    accuracyOnFile = 180

    criticalRateOnFile = 190

    nameOnFile = 20000

    f.seek(strengthOnFile)
    f.write(getNumberWithDummy(player.strength))

    f.seek(dexterityOnFile)
    f.write(getNumberWithDummy(player.dexterity))

    f.seek(vitalityOnFile)
    f.write(getNumberWithDummy(player.vitality))

    f.seek(energyOnFile)
    f.write(getNumberWithDummy(player.energy))

    f.seek(maxHealthOnFile)
    f.write(getNumberWithDummy(player.maxHealth))

    f.seek(healthOnFile)
    f.write(getNumberWithDummy(player.health))

    f.seek(maxManaOnFile)
    f.write(getNumberWithDummy(player.maxMana))

    f.seek(manaOnFile)
    f.write(getNumberWithDummy(player.mana))

    f.seek(defenseOnFile)
    f.write(getNumberWithDummy(player.defense))

    f.seek(magdefOnFile)
    f.write(getNumberWithDummy(player.magdef))

    f.seek(atkMeleeMinOnFile)
    f.write(getNumberWithDummy(player.atkMeleeMin))

    f.seek(atkMeleeMaxOnFile)
    f.write(getNumberWithDummy(player.atkMeleeMax))

    f.seek(atkRangedMinOnFile)
    f.write(getNumberWithDummy(player.atkRangedMin))

    f.seek(atkRangedMaxOnFile)
    f.write(getNumberWithDummy(player.atkRangedMax))

    f.seek(atkMagicMinOnFile)
    f.write(getNumberWithDummy(player.atkMagicMin))

    f.seek(atkMagicMaxOnFile)
    f.write(getNumberWithDummy(player.atkMagicMax))

    f.seek(goldOnFile)
    f.write(getNumberWithDummy(player.gold))

    f.seek(evasionOnFile)
    f.write(getNumberWithDummy(player.evasion))

    f.seek(accuracyOnFile)
    f.write(getNumberWithDummy(player.accuracy))

    f.seek(criticalRateOnFile)
    f.write(getNumberWithDummy(player.criticalRate))

    f.seek(nameOnFile)
    f.write(player.name)

    f.close()
    f = open('save.dat', 'r')
    f.seek(0)
    sha = hashlib.sha256()
    sha.update(f.read())
    f.close()

    s = open('save.hs', 'w')
    s.write(sha.hexdigest())
    s.close()
